<?php
class Captcha{
	private $_width;
	private $_height;
	private $_text;
	private $_color;
	private $_font;
	private $_fontSize;

	public function __construct(){
		$this->_width = 200;
		$this->_height = 40;
		$this->_font = 'font/font111.ttf';
		$this->_fontSize = 25;
	}

	public function create($text = ''){
		header('Content-type: image/jpeg');
		$this->_text = $text;
		$image = imagecreate($this->_width, $this->_height);
		imagecolorallocate($image, 255, 255, 255);
		$text_color = imagecolorallocate($image, 0, 0, 0);

		for($x = 0; $x < 80; $x ++ ){
			$x1 = rand(1, 100);
			$x2 = rand(1, 100);
			$y1 = rand(1, 100);
			$y2 = rand(1, 100);

			imageline($image, $x1, $y1, $x2, $y2, $text_color);
		}

		imagettftext($image, $this->_fontSize, 0, 15, 30, $text_color, $this->_font, $this->_text);
		imagejpeg($image);
	}
}